package com.cube.dp.cor.controller;

import com.cube.dp.base.response.ApiResult;
import com.cube.dp.cor.context.TransformContext;
import com.cube.dp.cor.filter.TransformFilterChain;
import com.cube.dp.cor.filter.TransformFilterChainFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author cube.li
 * @date 2021/12/23 15:36
 */
@RestController
@Slf4j
public class TransformController {

    @Autowired
    private TransformFilterChainFactory chainFactory;

    @GetMapping("st/{code}")
    public ApiResult<Void> transform(@PathVariable String code, HttpServletRequest request) {
        TransformContext context = TransformContext.of(request, code);
        TransformFilterChain chain = chainFactory.defaultFilterChain(context);
        chain.doFilter();
        return ApiResult.success();
    }
}
